! First homework assignment
! Object-based Fortran 95
! Paul F. Dubois

module hw1
    use precision
    implicit none

    contains

    function stats(x) result(y)
	  real(adequate), intent(in), dimension(:):: x
	  real(adequate) y(3), mean

	  mean = sum(x) / size(x)
	  y(1) = mean
	  y(2) = real(count(x > mean), adequate) / size(x)
	  y(3) = sum ((x - mean)**2) / size(x)
	end function stats

	function outer(x, y) result(z)
       real(adequate), intent(in):: x(:), y(:)
	   real(adequate) z(size(x), size(y))
	   integer i

	   do i = 1, size(x)
	      z(i, :) = x(i) * y
	   enddo
	end function outer

end module hw1

program test1
   use hw1
   implicit none

   real(adequate) x(5), y(5)

   x = (/ 1., 2., 3., 4., 5. /)
   y = 10 * x

   print *, stats(x)
   print *, outer(x, y)
end program test1

